using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerController : MonoBehaviour
{
    private Rigidbody2D rb;
    private Animator anim;
    public float speed;
    // Start is called before the first frame update
    void Start()
    {
        rb = GetComponent<Rigidbody2D>();
        anim = GetComponent<Animator>();
    }

    // Update is called once per frame
    void Update()
    {
        Movement();
    }
    void Movement()
    {
        if (Input.GetKey(KeyCode.W) && Input.GetKey(KeyCode.A))
        {
            rb.velocity = new Vector2(-speed * 0.7f, speed * 0.7f);
            anim.SetBool("move", true);
        }
        else if (Input.GetKey(KeyCode.W) && Input.GetKey(KeyCode.D))
        {
            rb.velocity = new Vector2(speed * 0.7f, speed * 0.7f);
            anim.SetBool("move", true);
        }
        else if (Input.GetKey(KeyCode.S) && Input.GetKey(KeyCode.A))
        {
            rb.velocity = new Vector2(-speed * 0.7f, -speed * 0.7f);
            anim.SetBool("move", true);
        }
        else if (Input.GetKey(KeyCode.S) && Input.GetKey(KeyCode.D))
        {
            rb.velocity = new Vector2(speed * 0.7f, -speed * 0.7f);
            anim.SetBool("move", true);
        }
        else if (Input.GetKey(KeyCode.W))
        {
            rb.velocity = new Vector2(0, speed);
            anim.SetBool("move", true);
        }
        else if (Input.GetKey(KeyCode.S))
        {
            rb.velocity = new Vector2(0, -speed);
            anim.SetBool("move", true);
        }
        else if (Input.GetKey(KeyCode.A))
        {
            rb.velocity = new Vector2(-speed,0);
            anim.SetBool("move", true);
        }
        else if (Input.GetKey(KeyCode.D))
        {
            rb.velocity = new Vector2(speed, 0);
            anim.SetBool("move", true);
        }
        else
        {
            rb.velocity = new Vector2(0, 0);
            anim.SetBool("move", false);
        }
    }
}
